package stream.collectors;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/6
 */
//1.将英文字符串的数组中的元素全部变为大写，以集合输出。将整数的数组中的元素全部加3，以集合输出。
//2.统计员工人数、平均工资、工资总额、最高工资、统计工资的所有信息。
//counting() 、averagingDouble()、maxBy()、summingInt()、summarizingDouble()
//3.将员工按薪资是否高于8000分为两部分
//4.将所有员工的名称用逗号拼接  joining(",")
class Employee {
    private String name;
    private int salary;


    public Employee() {
    }

    public Employee(String name, int salary) {
        this.name = name;
        this.salary = salary;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return salary
     */
    public int getSalary() {
        return salary;
    }

    /**
     * 设置
     * @param salary
     */
    public void setSalary(int salary) {
        this.salary = salary;
    }
    public String toString() {
        return "Employee{name = " + name + ", salary = " + salary + "}";
    }
}
public class CollectorsDemo2 {
    public static void main(String[] args) {
        Employee e1= new Employee("张三", 20000);
        Employee e2= new Employee("李四", 15000);
        Employee e3= new Employee("王五", 8000);
        Employee e4= new Employee("赵六", 10000);
        Employee e5= new Employee("钱七", 9000);
        Employee e6= new Employee("李八", 12000);
        List<Employee> employees = Arrays.asList(e1,e2,e3,e4,e5,e6);
        long count = employees.stream()
                .collect(Collectors.counting());
        System.out.println("人数: " + count);

        double avgSalary = employees.stream()
                .collect(Collectors.averagingDouble(Employee::getSalary));
        System.out.println("平均工资: " + avgSalary);

        int totalSalary = employees.stream()
                .collect(Collectors.summingInt(Employee::getSalary));
        System.out.println("工资总额: " + totalSalary);

        Optional<Integer> maxSalary = employees.stream()
                .collect(Collectors.maxBy(Comparator.comparingInt(Employee::getSalary))).map(Employee::getSalary);
        System.out.println("最高工资: " + maxSalary.orElse(0));

        DoubleSummaryStatistics salarydata = employees.stream()
                .collect(Collectors.summarizingDouble(Employee::getSalary));
        System.out.println("所有人员工资信息: " + salarydata);
        //System.out.println("平均工资:"+salarydata.getAverage());
//        System.out.println("工资总额：:"+salarydata.getSum());
//        System.out.println("最高工资:"+salarydata.getMax());

        System.out.println("-------------------工资分类--------------------------");
        Map<Boolean, List<Employee>> map = employees.stream()
                .collect(Collectors.partitioningBy(e -> e.getSalary() > 8000));
        System.out.println(map);
        System.out.println("---------------所有员工姓名-------------------");
        String names = employees.stream()
                .map(Employee::getName)
                .collect(Collectors.joining(","));
        System.out.println("员工姓名拼接结果: " + names);
    }
}